package com.hmkj.admin.controller.simulation;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.common.utils.StringUtils;
import com.hmkj.core.exception.BussinessException;
import com.hmkj.core.model.simulation.AccountSimulationModel;
import com.hmkj.core.po.account.AccountSimulation;
import com.hmkj.core.service.account.AccountSimulationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * create by ${hello} on ${date}
 */
@Controller
@RequestMapping(BaseController.BASE_URI)
public class AccountSimulationJsonController extends GenericController<Integer,AccountSimulation> {
   @Resource
   private AccountSimulationService accountSimulationService;
    /**
     * 模拟账户
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("simulation/account/json/list")
    public DtGrid userListJson(String dtGridPager) throws Exception {
        return accountSimulationService.getDtGridList(dtGridPager, AccountSimulationModel.class);
    }

    /**
     * 编辑资金
     * @param
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("simulation/account/json/edit")
    @RequiresPermissions("simulation:acc:edit")
    public ResultEntity editJson(Integer id,BigDecimal accountNum) throws  Exception{
        if(null == id){
            throw new BussinessException("参数错误");
        }
        if(accountNum.compareTo(BigDecimal.ZERO) == 0){
            throw new BussinessException("金额不能为0");
        }
        AccountSimulation accountSimulation = accountSimulationService.selectByPrimaryKey(id);
       if(null == accountSimulation){
           throw new BussinessException("模拟账户不存在");
       }
       accountSimulationService.handEditAccount(accountSimulation,accountNum);
        return ok();
    }
}
